package org.jeecg.modules.utils.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.business.job.AlartJob;
import org.jeecg.modules.utils.dto.SmsDto;
import org.jeecg.modules.utils.service.IAlertService;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.impl.JobExecutionContextImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Api(tags = "预警测试")
@RestController
@RequestMapping("/utils")
@Slf4j
public class AlertTestController {

    @Autowired
    private IAlertService alertService;
    @Autowired
    private AlartJob alartJob;

    @ApiOperation(value = "预警", notes = "预警")
    @PostMapping(value = "/send")
    public Result send() throws Exception {
        SmsDto smsDto = new SmsDto();
        smsDto.setTemplateCode("warehouse-safety");
        Map<String, Object> data = new HashMap<>();
        data.put("arg1", "南门仓库");
        data.put("arg2", "warning");
        smsDto.setData(data);
        alertService.send(smsDto);
        return Result.OK();

    }

    @ApiOperation(value = "取消预警", notes = "取消预警")
    @PostMapping(value = "/inactive")
    public Result inactive() throws Exception {
        SmsDto smsDto = new SmsDto();
        smsDto.setTemplateCode("warehouse-safety");
        Map<String, Object> data = new HashMap<>();
        data.put("arg1", "南门仓库");
        data.put("arg2", "warning");
        smsDto.setData(data);
        alertService.inActive(smsDto);
        return Result.OK();

    }

    @ApiOperation(value = "仓库预警", notes = "仓库预警")
    @GetMapping("/test")
    public Result test(JobExecutionContext context) throws JobExecutionException {
        alartJob.execute(context);
        return Result.ok();
    }

}
